//
//  CustomNoTradingPwdAlert.m
//  HuoBao
//
//  Created by chaiyanan on 15/12/22.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CustomNoTradingPwdAlert.h"
#define GetFinalResult(x,y,z,r) (IsIphone4?x:(IsIphone6P?r:(IsIphone5?y:z)))
#define ScaleForm5To6    1.172
//#define ScaleForm4To6    1.389
#define ScaleForm4To6    1.172
#define alertViewW       GetFinalResult(275/ScaleForm4To6,275/ScaleForm5To6,275,275*1.104)
#define alertViewH       GetFinalResult(183/ScaleForm4To6,183/ScaleForm5To6,183,183*1.104)
#define bgviewToDangbanW       GetFinalResult(45/ScaleForm4To6,45/ScaleForm5To6,45,45*1.104)
#define bgviewToDangbanH       GetFinalResult(192/ScaleForm4To6,192/ScaleForm5To6,192,192*1.104)

@interface CustomNoTradingPwdAlert ()
<UITextFieldDelegate>
{
    UIView*    bgview;
    UIView*    dangban;
    UILabel*   alertLabel;
}


@end

@implementation CustomNoTradingPwdAlert

- (instancetype)init{
    self = [super init];
    
    dangban = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    dangban.backgroundColor = [UIColor blackColor];
    dangban.alpha = 0.3;
    [self addSubview:dangban];
    
    bgview = [[UIView alloc]initWithFrame:CGRectMake(bgviewToDangbanW, bgviewToDangbanH, alertViewW, alertViewH)];
    bgview.backgroundColor = [LCCommon getColor:@"3d3e41"];
    bgview.alpha = 0;
    bgview.layer.cornerRadius = 4;
    [self addSubview:bgview];
    
    UILabel* topTitle = [self LabelWithRect:CGRectMake(0, 23, alertViewW, 22) textColor:[LCCommon getColor:@"ffffff"] textstr:@"未设置提现密码!" textfont:22 textstyle:NSTextAlignmentCenter];
    [bgview addSubview:topTitle];
    
    alertLabel = [self LabelWithRect:CGRectMake(0, 50, alertViewW, 60) textColor:[LCCommon getColor:@"b1b1b1"] textstr:@"您的账号尚未设置提现密码，如您需要,\n提现请先设置提现密码以便操作。" textfont:13 textstyle:NSTextAlignmentCenter];
    [bgview addSubview:alertLabel];
    
    UIView *horLine = [self makeLinewithRect:CGRectMake(0, alertViewH-45, alertViewW, 1/[UIScreen mainScreen].scale) Color:[LCCommon getColor:@"696969"] addview:bgview];
    UIView *verLine =[self makeLinewithRect:CGRectMake(alertViewW/2, alertViewH-45, 1/[UIScreen mainScreen].scale, 45) Color:[LCCommon getColor:@"696969"] addview:bgview];
    
    UIButton*  leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.tag = 2500;
    [leftBtn setTitle:@"去设置" forState:UIControlStateNormal];
    [leftBtn setTitleColor:[LCCommon getColor:@"ffffff"] forState:UIControlStateNormal];
    [leftBtn setFrame:CGRectMake(0, alertViewH -45, alertViewW/2-1, 45)];
    [leftBtn setBackgroundColor:[UIColor clearColor] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [bgview addSubview:leftBtn];
    
    UIButton*  rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.tag = 2501;
    [rightBtn setTitle:@"取消" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[LCCommon getColor:@"ffffff"] forState:UIControlStateNormal];
    [rightBtn setFrame:CGRectMake(alertViewW/2, alertViewH -45, alertViewW/2-1, 45)];
    [rightBtn setBackgroundColor:[UIColor clearColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [bgview addSubview:rightBtn];
    
    topTitle.textColor = [LCCommon getColor:@"d2d2d2"];
    [leftBtn setTitleColor:[LCCommon getColor:@"d2d2d2"] forState:UIControlStateNormal];
    [rightBtn setTitleColor:[LCCommon getColor:@"d2d2d2"] forState:UIControlStateNormal];
    [leftBtn.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
    [rightBtn.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
    
    [bgview bringSubviewToFront:horLine];
    [bgview bringSubviewToFront:verLine];
    bgview.clipsToBounds = YES;
    
    bgview.centerX = SCREEN_WIDTH/2;
    bgview.centerY = SCREEN_HEIGHT/2 - 40;
    if (isIphone4or5)
    {
        topTitle.height = 28;
        [topTitle setFont:[UIFont systemFontOfSize:20]];
        [alertLabel setFont:[UIFont systemFontOfSize:11]];
        topTitle.y = 14;
        alertLabel.y = 40;
        
    }
    else if(IsIphone6)
    {
        alertLabel.y = 55;
    }
    else
    {
        alertLabel.y = 70;
    }
    
    [leftBtn setBackgroundColor:[LCCommon getColor:@"343538"] forState:UIControlStateHighlighted];
    [rightBtn setBackgroundColor:[LCCommon getColor:@"343538"] forState:UIControlStateHighlighted];
    
    return self;
}

- (void)btnAction:(UIButton*)button{
    if (button.tag == 2500) {
        LLog(@"去设置");
        if (self.ActionClickToSetTradingPwd)
        {
            self.ActionClickToSetTradingPwd(self);
        }
    }else if(button.tag == 2501){
        LLog(@"取消");
        if (self.ActionClickToCancel) {
            self.ActionClickToCancel();
        }
        [self removeFromSuperview];
    }
    
}

-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
    //设置行距
    if (IsIphone6P)
    {
        [style setLineSpacing:10.0f];
    }
    else
    {
        [style setLineSpacing:7.0f];
    }
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [attStr length])];
    label.attributedText = attStr;
    label.textColor = color;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}

-(UIView *)makeLinewithRect:(CGRect)rect Color:(UIColor *)color addview:(UIView *)vi{
    UIView *line = [[UIView alloc]initWithFrame:rect];
    line.backgroundColor = color;
    [vi addSubview:line];
    return line;
}


- (void)showTradPasswordAlertView{
    [UIView animateWithDuration:0.25 animations:^{
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        bgview.backgroundColor = [LCCommon getColor:@"3d3e41"];
        bgview.alpha = 1;
    }completion:^(BOOL finished) {
        
    }];
}



@end
